package servlet;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.servlet.http.HttpServletRequest;

import service.IServiceManager;
import service.exception.ServiceException;
import bean.LoginCredential;
import business.user.UserAuthentication;

@SuppressWarnings("deprecation")
public class UserAction {
	
	private LoginCredential lc;
	
	public String Login(){
	   HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
 	   FacesContext context=FacesContext.getCurrentInstance();
 	   ValueBinding customer_binding=context.getApplication().createValueBinding("#{logincredential}");
 	   lc=(LoginCredential)customer_binding.getValue(context);
       
 	   System.out.println(lc.getUsername());
 	   System.out.println(lc.getPassword());
 	   	   
 	   IServiceManager serviceMgn = new UserAuthentication(request);
 	   try {
 		   serviceMgn.execute(UserAuthentication.SERVICE_LOGIN, lc);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 	   /*Register customer here using DAO function*/
 	   return null;
    }

	public String Logout(){
		return null;
	}

}
